package cn.csg.iotplatform.module.system.controller.admin.testingmanufacturer;

import cn.csg.iotplatform.framework.common.pojo.PageResult;
import cn.csg.iotplatform.module.system.controller.admin.testingmanufacturer.vo.DvTestingManufacturerPageReqVO;
import cn.csg.iotplatform.module.system.controller.admin.testingmanufacturer.vo.DvTestingManufacturerRespVO;
import cn.csg.iotplatform.module.system.controller.admin.testingmanufacturer.vo.DvTestingManufacturerSaveReqVO;
import cn.csg.iotplatform.module.system.dal.dataobject.testingmanufacturer.DvTestingManufacturerDO;
import cn.csg.iotplatform.module.system.service.testingmanufacturer.DvTestingManufacturerService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.csg.iotplatform.framework.common.pojo.CommonResult;
import cn.csg.iotplatform.framework.common.util.object.BeanUtils;
import static cn.csg.iotplatform.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 检测机构信息")
@RestController
@RequestMapping("/system/testing-manufacturer")
@Validated
public class DvTestingManufacturerController {

    @Resource
    private DvTestingManufacturerService dvTestingManufacturerService;

    @PostMapping("/create")
    @Operation(summary = "创建检测机构信息")
    // @PreAuthorize("@ss.hasPermission('im:dv-testing-manufacturer:create')")
    public CommonResult<String> createDvTestingManufacturer(@Valid @RequestBody DvTestingManufacturerSaveReqVO createReqVO) {
        return success(dvTestingManufacturerService.createDvTestingManufacturer(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新检测机构信息")
    // @PreAuthorize("@ss.hasPermission('im:dv-testing-manufacturer:update')")
    public CommonResult<Boolean> updateDvTestingManufacturer(@Valid @RequestBody DvTestingManufacturerSaveReqVO updateReqVO) {
        dvTestingManufacturerService.updateDvTestingManufacturer(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除检测机构信息")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('im:dv-testing-manufacturer:delete')")
    public CommonResult<Boolean> deleteDvTestingManufacturer(@RequestParam("ids") String ids) {
        dvTestingManufacturerService.deleteDvTestingManufacturer(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得检测机构信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('im:dv-testing-manufacturer:query')")
    public CommonResult<DvTestingManufacturerRespVO> getDvTestingManufacturer(@RequestParam("id") String id) {
        DvTestingManufacturerDO dvTestingManufacturer = dvTestingManufacturerService.getDvTestingManufacturer(id);
        return success(BeanUtils.toBean(dvTestingManufacturer, DvTestingManufacturerRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得检测机构信息分页")
    // @PreAuthorize("@ss.hasPermission('im:dv-testing-manufacturer:query')")
    public CommonResult<PageResult<DvTestingManufacturerRespVO>> getDvTestingManufacturerPage(@Valid DvTestingManufacturerPageReqVO pageReqVO) {
        PageResult<DvTestingManufacturerDO> pageResult = dvTestingManufacturerService.getDvTestingManufacturerPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DvTestingManufacturerRespVO.class));
    }

}